var COMMON_YELLOW = createColorWithRGBA(255, 153, 18, 255);
var COMMON_DARK = createColorWithRGBA(50, 51, 52, 255);
var COMMON_DARK_DEEP = createColorWithRGBA(40, 41, 42, 255);

var mainVC = new ViewController(false, true);
var mainView = mainVC.view;
mainVC.title = 'VRTDebugger';
mainView.backgroundColor = COMMON_DARK_DEEP;

function displayLabelS1() {
  Label.call(this);
  this.textAlignment = TextAlignmentCenter;
  this.textColor = whiteColor;
  this.fontSize = 35;
  this.backgroundColor = COMMON_DARK;
}

function displayTextFieldS1() {
  TextField.call(this);
  this.textColor = whiteColor;
  this.fontSize = 35;
  this.backgroundColor = COMMON_DARK;
}

var loginReq = new HttpRequest('https://21xa689434.imwork.net:23333/user/login4APP', function (data, info) {
  if(!data)
  {
    return;
  }
  var dataModel = data;
  if(!dataModel.isSuccess)
  {
    return;
  }

  var userData = dataModel.jsonData;
  if(!userData || userData == undefined)
  {
    return;
  }
  api_pushUrlWithParam('https://21xa689434.imwork.net:23333/public/tmp/VRTJSFramework/code/VRTDebugger/VRTDebuggerProj.js', userData);
});

mainVC.addCallBackViewDidLoad(function () {

  var blankLabel = new displayLabelS1();
  blankLabel.cornerRadius = 5;
  mainView.addSubView(blankLabel);
  blankLabel.vrt_layout.topEqualToView(mainView).leftEqualToView(mainView).heightIs(100).widthRatioToView(mainView, 1);

  var mainLabel = new displayLabelS1();
  mainLabel.text = 'VRTDebugger';
  mainView.addSubView(mainLabel);
  mainLabel.vrt_layout.topSpaceToView(blankLabel, 0).leftEqualToView(mainView).heightIs(100).widthRatioToView(mainView, 1);

  var accountLabel = new displayLabelS1();
  accountLabel.text = 'Account';
  mainView.addSubView(accountLabel);
  accountLabel.vrt_layout.topSpaceToView(mainLabel, 0).leftEqualToView(mainView).heightIs(100).widthIs(300);

  var accountTextField = new displayTextFieldS1();
  mainView.addSubView(accountTextField);
  accountTextField.vrt_layout.topSpaceToView(mainLabel, 0).leftSpaceToView(accountLabel, 0).heightIs(100).widthIs(mainView.width() - 300);

  var pwdLabel = new displayLabelS1();
  pwdLabel.text = 'Password';
  mainView.addSubView(pwdLabel);
  pwdLabel.vrt_layout.topSpaceToView(accountLabel, 0).leftEqualToView(mainView).heightIs(100).widthIs(300);

  var pwdTextField = new displayTextFieldS1();
  mainView.addSubView(pwdTextField);
  pwdTextField.vrt_layout.topSpaceToView(accountLabel, 0).leftSpaceToView(pwdLabel, 0).heightIs(100).widthIs(mainView.width() - 300);

  var commitBtn = new displayLabelS1();
  commitBtn.cornerRadius = 5;
  commitBtn.text = "Commit";
  commitBtn.backgroundColor = COMMON_YELLOW;
  mainView.addSubView(commitBtn);
  commitBtn.vrt_layout.topSpaceToView(pwdLabel, 0).leftEqualToView(mainView).heightIs(100).widthRatioToView(mainView, 1);

  commitBtn.addClick(function () {
    var encodePwd = api_encodeMD5B32(pwdTextField.text);
    loginReq.request({
      'userPhone' : accountTextField.text,
      'userPwd' : encodePwd.toLocaleUpperCase(),
      'userDevice' : api_platform()
    });
  });
  api_commitVC(mainVC);
});

